#include<iostream>
#include<algorithm>
using namespace std;

int main(int argc, char const *argv[])
{
    #ifdef _TEST_
    freopen("test.txt","r",stdin);
    #endif
    // input and vars
    const int MAX_NUM = 510;
    int N,M,S,D; cin>>N>>M>>S>>D;
    int Dist[MAX_NUM][MAX_NUM], Cost[MAX_NUM][MAX_NUM];
    fill(Dist[0],Dist[0]+MAX_NUM*MAX_NUM,INT32_MAX); fill(Cost[0],Cost[0]+MAX_NUM*MAX_NUM,INT32_MAX);
    for(int i = 0;i<M;++i)
    {
        int c1,c2,dis,cost; cin>>c1>>c2>>dis>>cost;
        Dist[c1][c2] = Dist[c2][c1] = dis;
        Cost[c1][c2] = Cost[c2][c1] = cost;
    }
    // shorest path itself is a weighless graph; repr by pre mat
    // 1 for connected and 0 for not
    int pre[MAX_NUM][MAX_NUM]={0}; 

    // run dijk and store path in pre
    int visited[MAX_NUM]={0}, pl[MAX_NUM];
    fill(pl,pl+N,INT32_MAX);
    pl[S] = 0;
    for(int _=0;_<N;++_)
    {
        int minpl = INT32_MAX, minid;
        for(int i = 0;i<N;++i)
        {
            if(!visited[i] && pl[i] < minpl){minpl = pl[i]; minid = i;}
        }
        visited[minid] = 1;
        // do update and build pre
        for(int i = 0;i<N;++i)
        {
            if(!visited[i] && Dist[minid][i] < INT32_MAX && pl[minid] +Dist[minid][i]  <= pl[i])
            {
                if(pl[minid] + Dist[minid][i] < pl[i])
                {
                    pl[i] = pl[minid]+Dist[minid][i];
                    fill(pre[i],pre[i]+N,0);
                }
                pre[i][minid] = 1;
            }
        }
    }
    // only pre is useful info, so reuse visited and pl
    // on pre and run dijkstra again; now Cost as weight
    // start from D
    fill(visited,visited+N,0);fill(pl,pl+N,INT32_MAX);
    int pre_final[MAX_NUM] = {0};
    pl[D] = 0;
    for(int _=0;_<N;++_)
    {
        int minid, minpl = INT32_MAX;
        for(int i = 0;i<N;++i)
        {
            if(!visited[i] && pl[i]<minpl){minid = i; minpl = pl[i];}
        }
        visited[minid] = 1;
        // do update
        for(int i = 0; i<N;++i)
        {
            if(!visited[i] && pre[minid][i] && pl[minid] + Cost[minid][i] <= pl[i])
            {
                pl[i] =  pl[minid] + Cost[minid][i] ;
                pre_final[i] = minid;
            }
        }
    }
    // int fpath[MAX_NUM], top = 0;
    int fcost = 0, fdist = 0;
    int cpos = S;
    do
    {
        // fpath[top++] = cpos;
        cout<<cpos<<" ";
        fdist += Dist[cpos][pre_final[cpos]];
        fcost += Cost[cpos][pre_final[cpos]];
        cpos = pre_final[cpos];
    }while(cpos != D);
    cout<<D<<" "<<fdist<<" "<<fcost;
    return 0;
}
